package code.rocky.week.s103;

import java.util.HashSet;

public class FindThePrefixCommonArray {


    public static void main(String[] args) {
        int[] A = new int[]{1,3,2,4};
        int[] A1 = new int[]{2,3,1};
        int[] B = new int[]{3,1,2,4};
        int[] B1 = new int[]{3,1,2};
        FindThePrefixCommonArray test = new FindThePrefixCommonArray();
        int[] thePrefixCommonArray = test.findThePrefixCommonArray(A1, B1);
        for (int i : thePrefixCommonArray) {
            System.out.print(i + " ");
        }
    }

    public int[] findThePrefixCommonArray(int[] A, int[] B) {
        int[] C = new int[A.length];
        int i = 0;
        HashSet<Object> hashSet = new HashSet<>();
        for (int j = 0; j < C.length; j++) {
            if (A[j] == B[j]) {
                i++;
            }
            if (hashSet.contains(A[j])) {
                i++;
            }
            if (hashSet.contains(B[j])) {
                i++;
            }
            hashSet.add(A[j]);
            hashSet.add(B[j]);
            C[j]=i;
        }
        return C;
    }
}
